var vm = new Vue({
    el:"#app",
    data:{
        dept:'',
        deptArea:'',
        parentDept:'',
        updateFlag:''
    },
    methods:{
        getDept:function () {
            let str = location.search;
            str = decodeURI(str);
            str = str.split("=")[1];
            axios({
                method:'post',
                url:'/dept/queryDeptInfo',
                params:{"deptName":str}
            }).then(function(result){
                vm.dept=result.data;
            }).catch(function (err) {
                console.log(err);
            })
        },
        getDeptArea:function () {
            axios({
                method:'post',
                url:'/dept/queryDeptArea',
            }).then(function(result){
                vm.deptArea=result.data;
            }).catch(function (err) {
                console.log(err);
            })
        },
        getDeptList:function () {
            let str = location.search;
            str = decodeURI(str);

            str = str.split("=")[1];
            axios({
                method:'post',
                url:'/dept/queryDeptListForUpdate',
                params:{"deptName":str}
            }).then(function(result){
                vm.parentDept=result.data;
            }).catch(function (err) {
                console.log(err);
            })
        },
        updateDept:function (){
            let flag = true;
            let deptName = $("input[name='deptName']").val();
            if (deptName === ""){
                flag = false;
            }
            let deptArea = $(".deptArea").val();
            if (deptArea === "请选择"){
                flag = false;
            }
            let deptFName = $(".parentDept").val();
            if (deptFName === "请选择"){
                flag = false;
            }
            if (flag){
                axios.post("/dept/updateDept",{deptName:deptName,deptArea:deptArea,deptFName:deptFName}).then(
                    function(result){
                        vm.updateFlag=result.data;
                        console.log(vm.updateFlag);
                        if (vm.updateFlag){
                            alert("修改成功");
                            location.href = "../../../../templates/sysManage/deptManage/deptList.html";
                        }else {
                            alert("修改失败");
                        }
                    },function (err) {
                        console.log(err);
                    }
                )
            }else {
                alert("您的信息还未填写完全");
            }
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getDept();
        this.getDeptList();
        this.getDeptArea();
    }
})